#include <stdio.h>
#include <stdlib.h>

int compare(void const* a, void const* b)
{
    int *left = (int*)a, *right = (int*)b;
    return *left - *right;
}

int main(int argc, char const *argv[])
{
    int n, k, list[100086], sub[100086], sum = 0;
    int i, j;
    scanf("%d %d", &n, &k);
    
    for (i = 0; i < n; i++) 
        scanf("%d", &list[i]);
    qsort(list, n, sizeof(int), compare);
    
    for (i = 0; i < n - 1; i++)
        sub[i] = list[i + 1] - list[i];
    qsort(sub, n - 1, sizeof(int), compare);
    
    for (i = 0; i < k; i++) 
        sum += sub[i];
    
    printf("%d", sum);

    return 0;
}
